package com.pat.java.base.io;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;

public class UseRandom {
	
	public void printStr(){
		String a=getClass().getClassLoader().getResource(".").getPath();//当前项目根下的bin目录 
		String b=getClass().getResource("").getPath(); //得到类的当前目录
		String d=getClass().getResource("/").getPath(); //当前项目根下的bin目录
		String e=System.getProperty("user.dir"); ////当前项目根目录
		
		System.out.println(a); 
		System.out.println(b); 
		System.out.println(d); 
		                  System.out.println(e); 
		System.out.println("*********************"); 
	}
	public static void main(String[] args) {
		try {
			RandomAccessFile f = new RandomAccessFile("/home/liuwenliang/公共的/eclipse_workspace/Java/src/com/liuwenliang/IO/Hello.txt", "rw");
			long flag = 0;
			long len = f.length();
			while (flag < len) {
				String s = f.readLine();
				System.out.println(parseChinese(s));
				flag = f.getFilePointer();
			}
			f.writeChar('O');
			f.writeChar('K');
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
	}

	public static String parseChinese(String inStr) {
		String s = null;
		byte temp[];
		if (inStr == null) {
			return new String("");
		}
		try {
			temp = inStr.getBytes("iso-8859-1");
			s = new String(temp);
		} catch (UnsupportedEncodingException e) {
			System.out.println(e.toString());
		}
		return s;
	}
}